package com.yalantis.ucrop.view;

import com.yalantis.ucrop.ResourceTable;
import com.yalantis.ucrop.util.Config;
import ohos.agp.components.AttrSet;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.StackLayout;
import ohos.app.Context;

public class UCropView extends StackLayout {

    StackLayout.LayoutConfig layoutConfig = new StackLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT);

    private final GestureCropImageView mGestureCropImageView;
    private final OverlayView mViewOverlay;

    public UCropView(Context context, AttrSet attrs) {
        super(context, attrs, "0");

        setLayoutConfig(layoutConfig);

        LayoutScatter.getInstance(context).parse(ResourceTable.Layout_ucrop_view, this, true);
        mGestureCropImageView = (GestureCropImageView) findComponentById(ResourceTable.Id_image_view_crop);
        mViewOverlay = (OverlayView) findComponentById(ResourceTable.Id_view_overlay);

        Config a = new Config();
        mViewOverlay.processStyledAttributes(a);
        mGestureCropImageView.processStyledAttributes(a);



        setListenersToViews();
    }

    private void setListenersToViews() {
        mGestureCropImageView.setCropBoundsChangeListener(mViewOverlay::setTargetAspectRatio);
        mViewOverlay.setOverlayViewChangeListener(mGestureCropImageView::setCropRect);
    }

    public GestureCropImageView getCropImageView() {
        return mGestureCropImageView;
    }


    public OverlayView getOverlayView() {
        return mViewOverlay;
    }
}